This has probably already been answered but I was running into the same problem as you and couldn't find an answer.
Maybe if I post it here I will be able to find it the next time I run into it. :-)
I think this will work for you
get-childitem C:\inetpub\logs\LogFiles -include *.log -recurse | where-object { $_.LastAccessTime -lt (Get-Date).AddDays(-14) -and $_.LastWriteTime -lt (Get-Date).AddDays(-14) } | remove-item -ErrorAction
SilentlyContinue -Confirm:$false
replace *.log without ever wildcard you need.
I was executing this
get-childitem -Recurse c:\logs\ | where {$_.LastWriteTime -le $now.AddDays(-30)} | del -whatif
and getting the same as you
Confirm
The item at
Microsoft.Powershell.Core\FileSystem::C:\logs\blah has children and the Recurse parameter was not specified. If you continue, all children
will be removed with the item. Are you sure you want to continue?
I replaced it with
get-childitem -Recurse c:\logs\ -include *log*| where {$_.LastWriteTime -le $now.AddDays(-30)} | del -whatif
and like magic no more prompts.
-
Edited by
thisissilly2
Thursday, May 31, 2012 8:41 PM